//
//  AppDelegate.m
//  JiFengDaRen
//
//  Created by SH_iOS on 16/1/14.
//  Copyright © 2016年 SH_iOS. All rights reserved.

//微信分享

#import "CYLPlusButtonSubclass.h"
#import "AppDelegate.h"
#import <AVFoundation/AVFoundation.h>
#import "IQKeyboardManager.h"

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"


@interface AppDelegate ()<UIAlertViewDelegate>


@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    //开启键盘管理
    [IQKeyboardManager sharedManager].enable = YES;
    
    //app不会随着静音键和屏幕关闭而静音,可在后台播放声音
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    
    //检测网络
    [self setupReachability];
    //初始化keywindow
    [self initRootKeyWindow];
    
    //去掉导航条下面的线
    [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
    [self.window makeKeyAndVisible];
    
//    [PPNetworkHelper openLog];
    
    return YES;
}

#pragma mark - 初始化window
- (void)initRootKeyWindow{
    
    NSData *cookiesdata = [[NSUserDefaults standardUserDefaults] objectForKey:KLoginStatusCookie];
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    if (cookiesdata != nil ) {
        CYLTabBarController *rootViewController = [[[JFTabbarControllerConfig alloc]init] tabBarController];
        self.window.rootViewController = rootViewController;
        
        
        if([cookiesdata length]) {
            NSArray *cookies = [NSKeyedUnarchiver unarchiveObjectWithData:cookiesdata];
            NSHTTPCookie *cookie;
            for (cookie in cookies) {
                [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
            }
        }
        
    }else{
        self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[JFLoginViewController alloc]init]];
    }
    
}

#pragma mark  - 配置网络检测
- (void)setupReachability{
    
    [SHNetworkReachabilityManager  startMonitoringNetWorkStatuComplete:^(NSInteger status) {

        switch (status) {
            case 1:{
                SHLog(@"手机流量上网");
            }
                break;
            case 2:{
                SHLog(@"WIFI上网");
            }
                break;
            default:{
                SHLog(@"没网");
            }
                break;
        }


    }];

}

- (void)applicationWillResignActive:(UIApplication *)application {
    
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    
}

- (void)applicationWillEnterForeground:(UIApplication *)application {

}

- (void)applicationWillTerminate:(UIApplication *)application {

}

@end

